package com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.controller;

import com.yonyou.ucf.mdf.app.isvdxq.ReturnResult.DataResult;
import com.yonyou.ucf.mdf.app.isvdxq.common.DxqConfig;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.entity.DeviceAddDto;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.entity.DeviceListEntity;
import com.yonyou.ucf.mdf.app.isvdxq.firstpart.device.service.DeviceListService;
import com.yonyou.ucf.mdf.app.isvdxq.other.service.BaseService;
import com.yonyou.ucf.mdf.app.isvdxq.utils.RequestTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = {DxqConfig.pre_apiUrl+"/device",DxqConfig.pre_pcUrl+"/device"})
public class DeviceListController {

    @Autowired
    BaseService baseService;
    @Autowired
    private DeviceListService deviceListService;

    /**
     * 根据条件查询分页的设备列表
     *
     * @param request    信息
     * @param deviceName 设备名称
     * @param deviceCode 设备编码
     * @param status     设备状态
     * @param page       页面
     * @param pagesize   页面大小
     * @return 返回列表
     */
    @RequestMapping("/GetDeviceListPage")
    public DataResult GetDeviceListPage(HttpServletRequest request, String deviceName, String deviceCode, String deviceinfo, String status,String type,
                                    @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceListService.getDeviceListPage(tenantId, deviceName, deviceCode, deviceinfo, status, type, page, pagesize);
    }

    /**
     * 获取设备列表 /device/GetDeviceList
     * @param request
     * @param deviceName
     * @param deviceCode
     * @param deviceinfo
     * @param status
     * @param type
     * @param id id=0:添加设备  id!=0:修改设备
     * @return
     */
    @RequestMapping("/GetDeviceList")
    public DataResult GetDeviceList(HttpServletRequest request, String deviceName, String deviceCode, String deviceinfo, String status,String type, String id) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceListService.SelectDeviceList(tenantId, deviceName, deviceCode, deviceinfo, status, type, id);
    }

    /**
     * 根据ID 查询设备信息
     *
     * @param request 请求信息
     * @param id      设备id
     * @return 返回设备信息
     */
    @RequestMapping("/GetDeviceListById")
    public DataResult GetDeviceListById(HttpServletRequest request, String id) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceListService.getDeviceById(tenantId, id);
    }
    
    /**
     * 添加设备信息
     *
     * @param request      请求信息
     * @param deviceAddDto 添加设备列表
     * @return 返回格式化请求信息
     */
    @RequestMapping("/AddDevice")
    public DataResult AddDevice(HttpServletRequest request, @RequestBody List<DeviceAddDto> deviceAddDto) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceListService.AddDevice(tenantId, deviceAddDto);
    }

    /**
     * 删除设备信息
     * @param request 请求内容
     * @param id 设备id
     * @return 格式化返回
     */
    @RequestMapping("/DeleteDevice")
    public DataResult DelectDevice(HttpServletRequest request, String id) {
        return deviceListService.DeleteDevice(id);
    }

    /**
     * 修改设备信息
     * @param request 请求内容
     * @param id 设备id
     * @param deviceEntity 设备信息实体
     * @return 格式化返回
     */
    @RequestMapping("/ModifyDevice")
    public DataResult ModifyDevice(HttpServletRequest request, String id, @RequestBody DeviceListEntity deviceEntity) {
        return deviceListService.ModifyDevice(id,deviceEntity);
    }

    /**
     * 根据Ids 排外的获取设备信息
     * @param request reque
     * @param Ids ids
     * @return
     */
    @RequestMapping("/GetDeviceListExcludeIds")
    public DataResult GetDeviceList(HttpServletRequest request, String Ids) {
        String tenantId = baseService.getTenantId(request);
        String userId = RequestTool.getHeaderAndParameter(request, DxqConfig.DXQ_userId);
        return deviceListService.getDeviceList(tenantId,Ids);
    }


}
